package com.zxkj.commonpatrol.repoisity;

import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.constant.ItrackConstant;
import com.czy.basecommon.utils.tools.SPUtils;
import com.zxkj.commonpatrol.model.post.PointNewEvent;
import com.zxkj.commonpatrol.model.post.PostDevTypeInfo;
import com.zxkj.commonpatrol.model.response.DevTypeExtendInfo;
import com.zxkj.commonpatrol.model.response.PointInspectEvent;
import com.zxkj.commonpatrol.model.response.Questions;
import com.zxkj.commonpatrol.net.ETFApiHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import okhttp3.ResponseBody;

public class AddEventRepoisity extends BaseRepository {
    public AddEventRepoisity() {

    }

    public void getQuestList(MyBaseDataCallBack<List<String>> myBaseDataCallBack) {
        List<String> datas = new ArrayList<>();
        datas.add("机身状态是否良好?");
        datas.add("机身状态是否良好?");
        datas.add("机身状态是否良好?");
        datas.add("机身状态是否良好?");
        datas.add("机身状态是否良好?");
        myBaseDataCallBack.onDataSuccessCallBack(datas);

    }


    public void GetPointInspectEventInfo(String RouteInspectNo, String PointNo, String  EventNo,MyBaseDataCallBack mDataCallBack) {
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);

        PostDevTypeInfo bean=new PostDevTypeInfo();
        bean.setEventNo(EventNo);
        bean.setPointNo(PointNo);
        bean.setRouteInspectNo(RouteInspectNo);
        ETFApiHelper.geRadomApi().GetPointInspectEventInfo(map,new BaseHttpUtil<PostDevTypeInfo>().convertVo2Json(bean))
                .compose(Transformer.<PointInspectEvent>switchSchedulers())
                .subscribe(new CommonObserver<PointInspectEvent>() {

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(PointInspectEvent s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }


    public  void GetEventQuests(String RouteInspectNo, String PointNo,MyBaseDataCallBack mDataCallBack){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);

        PostDevTypeInfo bean=new PostDevTypeInfo();

        bean.setPointNo(PointNo);
        bean.setRouteInspectNo(RouteInspectNo);
        ETFApiHelper.geRadomApi().GetEventQuests(map,new BaseHttpUtil<PostDevTypeInfo>().convertVo2Json(bean))
                .compose(Transformer.<List<Questions>>switchSchedulers())
                .subscribe(new CommonObserver<List<Questions>>() {

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(List<Questions> s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }

    //保存

    public void Save(PointNewEvent event,MyBaseDataCallBack  mDataCallBack ){
        HashMap<String,Object> map=new HashMap<String, Object>();
        map.put("LoginId", SPUtils.get(ItrackConstant.LOGINID,""));
        map.put("Token", SPUtils.get(ItrackConstant.TOKEN,""));
        map.put("Lang", 1);


        ETFApiHelper.geRadomApi().SaveEvent(map,new BaseHttpUtil<PointNewEvent>().convertVo2Json(event))
                .compose(Transformer.<ResponseBody>switchSchedulers())
                .subscribe(new CommonObserver<ResponseBody>() {

                    @Override
                    protected void onError(String errorMsg) {
                        mDataCallBack.onDataFailCallBack(404,errorMsg);
                    }

                    @Override
                    protected void onSuccess(ResponseBody s) {

                        //回调数据
                        mDataCallBack.onDataSuccessCallBack(s);
                    }
                });
    }

}
